import Router from '@koa/router';
import TenantController from '@/controllers/TenantController';
import { auth, requirePermission } from '@/middlewares';
import { PermissionAction } from '@/types';

const router = new Router({
  prefix: '/api/tenants',
});

/**
 * 租户管理路由
 */

// 获取租户列表
router.get(
  '/',
  auth,
  requirePermission('tenant', PermissionAction.READ),
  TenantController.list.bind(TenantController),
);

// 创建租户
router.post(
  '/',
  auth,
  requirePermission('tenant', PermissionAction.CREATE),
  TenantController.create.bind(TenantController),
);

// 获取租户详情
router.get(
  '/:id',
  auth,
  requirePermission('tenant', PermissionAction.READ),
  TenantController.getById.bind(TenantController),
);

// 更新租户
router.put(
  '/:id',
  auth,
  requirePermission('tenant', PermissionAction.UPDATE),
  TenantController.update.bind(TenantController),
);

// 删除租户
router.delete(
  '/:id',
  auth,
  requirePermission('tenant', PermissionAction.DELETE),
  TenantController.delete.bind(TenantController),
);

// 激活租户
router.post(
  '/:id/activate',
  auth,
  requirePermission('tenant', PermissionAction.UPDATE),
  TenantController.activate.bind(TenantController),
);

// 暂停租户
router.post(
  '/:id/suspend',
  auth,
  requirePermission('tenant', PermissionAction.UPDATE),
  TenantController.suspend.bind(TenantController),
);

// 获取租户统计信息
router.get(
  '/:id/stats',
  auth,
  requirePermission('tenant', PermissionAction.READ),
  TenantController.getStats.bind(TenantController),
);

export default router;

